import { createApp } from "vue";
import router from "@/router/index.js";
import pinia from "@/stores";
import "@/assets/main.less";
import "@/styles/index.scss"; // global css
//dayjs
import * as dayjs from "dayjs";
//引入插件
import * as relativeTime from "dayjs/plugin/relativeTime.js";
import * as isLeapYear from "dayjs/plugin/isLeapYear"; // 导入插件
import "dayjs/locale/zh-cn"; // 导入本地化语言
//使用插件 用啥插件自己加
dayjs.extend(isLeapYear); // 使用插件
dayjs.locale("zh-cn"); // 使用本地化语言
dayjs.extend(relativeTime);
import App from "./App.vue";
const app = createApp(App);
app.config.globalProperties.$dayjs = dayjs;
// 注册全局组件
import ElementPlus from "element-plus";
app.use(ElementPlus, { zIndex: 3000 });

// 引入SvgIcon.vue组件
import SvgIcon from "@/components/SvgIcon.vue";
import "virtual:svg-icons-register"; // svg注册脚本
// 注册全局图标icon
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
// 暗黑主题css样式文件
import "element-plus/theme-chalk/dark/css-vars.css";

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

// 登录页验证码插件
import MakeitCaptcha from "makeit-captcha";
import "makeit-captcha/dist/captcha.min.css";
app.use(MakeitCaptcha);

// 表单中文
import zhCn from "element-plus/es/locale/lang/zh-cn";
app.use(ElementPlus, {
  locale: zhCn,
});
// 引入MotionPlugin动画插件
import { MotionPlugin } from "@vueuse/motion";

app.use(MotionPlugin);
// 将SvgIcon.vue组件注册为全局组件
app.component("svg-icon", SvgIcon);
app.use(pinia);
import { useUserStore } from "@/stores/user.js";
const userStore = useUserStore();
userStore.addAsyncRoute();
app.use(router);

app.mount("#app");
